<%-- 
    Document   : register
    Created on : Feb 22, 2012, 2:48:17 PM
    Author     : 013v
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="Model.ProductManager"%>

<%
    String loginAttempt = request.getParameter("loginAttempt");
    if (loginAttempt != null) {
        boolean isValid = true;

        if (loginAttempt.indexOf("<") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(">") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("\"") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("/") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(":") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(";") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("=") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("|") > -1) {
            isValid = false;
        }

        if (isValid == false) {
            loginAttempt = null;
        }
        }       
    String authAttempt = request.getParameter("auth");
    if (authAttempt != null) {
        boolean isValidAuth = true;

        if (authAttempt.indexOf("<") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf(">") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf("\"") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf("/") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf(":") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf(";") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf("=") > -1) {
            isValidAuth = false;
        } else if (authAttempt.indexOf("|") > -1) {
            isValidAuth = false;
        }

        if (isValidAuth == false) {
            authAttempt = null;
        }     
    }          
%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/foo.css" type="text/css"></link>
        <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen">
        <title>Foobar</title>  
        <link type="text/css" href="css/redmond/jquery-ui-1.8.17.custom.css" rel="stylesheet" />	
        <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
        <script type="text/javascript" src="js/hoverIntent.js"></script>
        <script type="text/javascript" src="js/superfish.js"></script>         
        <script type="text/javascript" src="js/registerValidation.js"></script>
        <script type="text/javascript" src="js/SearchValidation.js"></script>

        <script type="text/javascript">
            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });



            function checkAuth(){
              if(<%=request.getParameter("loginAttempt")%>==false && isValid){
                 document.write('<span class="errLog">Authentication failed.</span>');
               }
            }
            
            function captcha(){
                if(<%=request.getParameter("auth")%>==false && isValidAuth){
                    document.getElementById("errorcaptcha").innerHTML = 'Enter the correct code.';
                }
            }

            $(document).ready(function() {
                $('#datepicker').datepicker({
                    inline: true,
                    dateFormat: 'yy-mm-dd'
                   
                });
            }
        );
		
        </script>
    </head>
    <body class="bg">
        <script type="text/javascript">checkAuth(); captcha();</script>
        <br/>
        <div class="hmenu">
            <img src="images/head.png" style="float: left; margin-left:20px;"></img>
            <div class="log">
                <% if (request.getSession(true).getAttribute("username") != null) {%>
                <span>Hello <%=session.getAttribute("username")%>!</span><br>
                <span style="font-weight: normal; font-size: 10px;">You have 0 items in your cart.</span>
                <div id="nav">
                    <ul class="top">
                        <li><a href="viewCart.jsp">View Cart</a></li>
                        <li><a href="checkOut.jsp">Checkout</a></li>
                        <li><a href="viewProfile.jsp">Account Details</a></li>
                        <li><a href="LogoutServlet">Log out</a></li>
                    </ul>
                </div>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="LoginServlet">
                    <label>Username:</label><input type="text" name="username"/><br/>
                    <label>Password:</label><input type="password" name="password"/><br/>
                    <input style="float:right;" type="submit" value="Log in" name="submit"/>
                </form>
                <% }%>
            </div>
            <ul class="sf-menu">
                <li class="current">
                    <a href="index.jsp">Home</a>
                </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                                        <%
                ResultSet rs = new ProductManager().getProductTypes();
                while(rs.next()){
                %>
                        <li>
                            <a href="products.jsp?prd=<%=rs.getInt("ProductTypeID")%>"><%=rs.getString("ProductType")%></a>
                        </li>
                <%}%>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <form action="results.jsp">
                            <input type="text" name="search" placeholder="Enter your search"/>
                            <button type="submit" onClick="return SearchValidation(this.form);">Go</button>
                    </form>
                </li>
            </ul>
        </div>
        <div class="content">
            <h2>Sign up here!</h2>
            <h6>*Username should be at least 6 characters with no special characters.<br/>
                *Password should be at least 8 characters. <br/>
                *All fields are required.
            </h6>
            <hr width="500px"/>
            <form id="signup" method="post" action="CustomerRegister">

                Username:
                <input name="username" type="text">
                <span class="erMes" id="errorusername"></span><br>

                Password:
                <input name="password" type="password">
                <span class="erMes" id="errorpassword"></span><br>    

                Re-type Password:
                <input name="retypepassword" type="password" class="in"/> 
                <br>
                <hr width="500px"/>

                <p><b>Personal Information</b></p>
                Name:
                <input name="fname" type="text" placeholder="First name">
                <input name="minitial" id ="minitial"type="text" style="width:30px;" placeholder="M.I.">
                <input name="sname" id ="sname" type="text" placeholder="Last name">
                <span class="erMes" id="errorname"></span><br>

                E-mail address:
                <input name="email" type="text" placeholder="E-mail">
                <span class="erMes" id="erroremail"></span><br>

                Billing Address:
                <input name="Bhouseno" type="text" placeholder="House number">
                <input name="Bst" type="text" placeholder="Street number">
                <input name="Bsubd" type="text" placeholder="Subdivision">
                <input name="Bcity" type="text" placeholder="City">
                <input name="Bzipcode" type="text" placeholder="Zip code">
                <input name="Bcountry" type="text" placeholder="Country">
                <span class="erMes"id="errorbilling"></span><br>

                Delivery Address:
                <input name="Dhouseno" type="text" placeholder="House number">
                <input name="Dst" type="text" placeholder="Street number">
                <input name="Dsubd" type="text" placeholder="Subdivision">
                <input name="Dcity" type="text" placeholder="City">
                <input name="Dzipcode" type="text" placeholder="Zip code">
                <input name="Dcountry" type="text" placeholder="Country">
                <span class="erMes" id="errordelivery"></span><br><br/>

                <hr width="500px"/>

                <p><b>Credit card information</b></p>
                Name on card:<input type="text" name="fcardname" placeholder="First Name"> <input type="text" name="scardname" placeholder="Last Name">
                <span class="erMes"id="errorcardname"></span><br>

                Type of card:
                <select name="cardType">
                    <option value="---" SELECTED>-------------------</option>
                    <option value="masterCard">Master Card</option>
                    <option value="visa">Visa</option>
                </select>
                <span class="erMes" id="errorcardtype"></span><br>

                Credit card number:
                <input type="text" name="cardNumber" placeholder="Credit card number">
                <span class="erMes"id="errorcardnumber"></span><br>


                Expiry Date:
                <input name="expiry" type="text" id="datepicker"/>
                <span class="erMes" id="errorcardexpiry"></span>
                <br/>


                <hr width="500px"/>
                <p><b>Security Question</b></p>
                Question:
                <select name="secQ">
                    <option value="---" SELECTED>------------------------------------------------------------------------------------</option>
                    <option value="hero">Who was your childhood hero?</option>
                    <option value="grandma">What is your grandmother's first name?</option>
                    <option value="mom">What is your mother's middle name? </option>
                    <option value="teach">What is the last name of your favorite high school teacher?</option>
                    <option value="toy">What was the name of your first stuffed animal?</option>
                    <option value="friend">What is the name of your favorite childhood friend? </option>
                    <option value="street">What street did you live on in third grade?</option>
                </select>
                <span class="erMes" id="errorsecQ"></span>
                <br/>
                Answer: <input type="text" name="secA"/>
                <span class="erMes" id="errorsecA"></span>
                <br/><br/>
                
                <br/>
                <button type="submit" name="signup" onClick="return validateAll(this.form);" 
                        style="float:right; margin-right: 150px;">Submit</button>
            </form>
        </div>
    </body>
</html>
